package com.enpronomics.pcall.receivers;

import com.enpronomics.pcall.GetLocation;
import com.enpronomics.pcall.LocationResult;
import com.enpronomics.pcall.MyLocation;
import com.enpronomics.pcall.ServiceManager;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.IBinder;
import android.widget.Toast;

public class PanicService extends Service {
	
	@Override
	public void onCreate() {
		Toast.makeText(this, "Panic Started", Toast.LENGTH_LONG).show();
		new MyLocation().init(this, new MyLocation.LocationResult() {
			@Override
			public void gotLocation(Location location) {
				String locationStr;
				if (location == null)
					locationStr = "No location Found";
				else
					locationStr = ServiceManager.getLocationStr(location);
				String name = ServiceManager.getStringSetting(PanicService.this,	ServiceManager.KEY_NAME);
				String currentTimeString = ServiceManager.getCurrentDate();
				ServiceManager.sendSMS(PanicService.this, ServiceManager.getStringSetting(PanicService.this, ServiceManager.KEY_PANIC_SMS_NUMBER), "My Location is:"+ locationStr +";"+ name + ";" + currentTimeString);
				PanicService.this.stopSelf();
			}
		});
//		new GetLocation(this, new LocationResult() {
//			@Override
//			public void locationGot(Location location) {
//				String locationStr;
//				if (location == null)
//					locationStr = "No location Found";
//				else
//					locationStr = ServiceManager.getLocationStr(location);
//				ServiceManager.sendSMS(PanicService.this, "01226337731", "My Location is:"+locationStr);
////				PanicService.this.stopSelf();
//			}
//		});
		
//		ServiceManager.call(this, "01226337731");
//		Toast.makeText(this, "Making call", Toast.LENGTH_LONG).show();
	}
	
	@Override
	public IBinder onBind(Intent arg0) {
		// TODO Auto-generated method stub
		return null;
	}

}
